<template>
  <div>
    <n-drawer v-model:show="showModal" :width="dialogWidth">
      <n-drawer-content title="拍品管理详情" closable>
        <n-spin :show="loading" description="请稍候...">
          <n-descriptions label-placement="left" class="py-2" :column="1">
            <n-descriptions-item label="抢购">
              <n-tag :type="dict.getType('auctionOption', formValue.auctionId)" size="small" class="min-left-space">
                {{ dict.getLabel('auctionOption', formValue.auctionId) }}
              </n-tag>
            </n-descriptions-item>
            <n-descriptions-item label="商品">
              <n-tag :type="dict.getType('productOption', formValue.productId)" size="small" class="min-left-space">
                {{ dict.getLabel('productOption', formValue.productId) }}
              </n-tag>
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                起拍价格
              </template>
              {{ formValue.basePrice }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                最低出价
              </template>
              {{ formValue.minBidPrice }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                开始日期
              </template>
              <n-time type="date" :time="formValue.auctionStartDate" format="yyyy-MM-dd" />
            </n-descriptions-item>

            <n-descriptions-item>
              <template #label>
                结束日期
              </template>
              <n-time type="date" :time="formValue.auctionEndDate" format="yyyy-MM-dd" />
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                开始时间
              </template>
              {{ formValue.startTime }}
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                结束时间
              </template>
              {{ formValue.endTime }}
            </n-descriptions-item>
            <n-descriptions-item label="每周运行时间">
              <template v-for="(item, key) in formValue.weekday" :key="key">
                <n-tag :type="dict.getType('weekday', item)" size="small" class="min-left-space">
                  {{ dict.getLabel('weekday', item) }}
                </n-tag>
              </template>
            </n-descriptions-item>
            <n-descriptions-item>
              <template #label>
                数量
              </template>
              {{ formValue.count }}
            </n-descriptions-item>
          </n-descriptions>
        </n-spin>
      </n-drawer-content>
    </n-drawer>
  </div>
</template>

<script lang="ts" setup>
  import { computed, ref } from 'vue';
  import { useMessage } from 'naive-ui';
  import { View } from '@/api/auctionProductMapper';
  import { State, newState } from './model';
  import { adaModalWidth } from '@/utils/hotgo';
  import { getFileExt } from '@/utils/urlUtils';
  import { useDictStore } from '@/store/modules/dict';
import { dateToTimestamp } from '@/utils/dateUtil';

  const message = useMessage();
  const dict = useDictStore();
  const loading = ref(false);
  const showModal = ref(false);
  const formValue = ref(newState(null));
  const dialogWidth = computed(() => {
    return adaModalWidth(580);
  });
  const fileAvatarCSS = computed(() => {
    return {
      '--n-merged-size': `var(--n-avatar-size-override, 80px)`,
      '--n-font-size': `18px`,
    };
  });

  // 下载
  function download(url: string) {
    window.open(url);
  }

  // 打开模态框
  function openModal(state: State) {
    showModal.value = true;
    loading.value = true;
    View({ id: state.id })
      .then((res) => {
        formValue.value = res;
        console.log('res', res);
        // formValue.value.auctionStartDate = dateToTimestamp(res.startTime);
      })
      .finally(() => {
        loading.value = false;
      });
  }

  defineExpose({
    openModal,
  });
</script>

<style lang="less" scoped></style>
